package com.example.demo.service.impl;

import com.example.demo.dao.RankDao;
import com.example.demo.dto.RankDto;
import com.example.demo.service.DZDPScratchService;
import com.example.demo.service.RankService;
import com.xiaoleilu.hutool.util.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ZhengWei
 * @Description
 * @date 2020/7/17 3:32 下午
 */
@Service
@Transactional
public class RankServiceImpl implements RankService {
    @Autowired
    private DZDPScratchService scratchService;
    @Autowired
    private RankDao rankDao;

    @Override
    public List<RankDto> getRankList(Integer cityId, Integer skuId) {
        List<RankDto> rankList;
        rankList = rankDao.getRankList(cityId, skuId);
        if (CollectionUtil.isEmpty(rankList)) {
            scratchService.scratchRank(cityId, skuId);
            rankList = rankDao.getRankList(cityId, skuId);
        } else {
            System.out.println("从数据库读取");
        }
        return rankList;
    }
}
